﻿using System;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using Sharp.Infrastructure.Crosscutting;

namespace Sharp.Services.Models
{
    [HubName("logHub")]
    public class LogMonitor : Hub
    {
        private static object _ontime;

        public LogMonitor()
        {
            if (_ontime == null)//本应用程序只注册一次事件
            {
                _ontime = new object();
                LogHelper.OnLogRecorded += LogHelper_OnLogRecorded;
            }
        }

        public void Send(string logJson)
        {
            Clients.All.wirteLog(logJson);
        }


        private void LogHelper_OnLogRecorded(object sender, EventArgs e)
        {
            this.Send(sender.ToString());
        }
    }
}